package com.xiaoy.core.base.security.user.entity;

import java.io.Serializable;

import javax.persistence.CascadeType;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.hibernate.annotations.Cache;
import org.hibernate.annotations.CacheConcurrencyStrategy;

import com.xiaoy.core.base.security.role.entity.Role;
import com.xiaoy.core.base.util.store.config.ConfigTable;
import com.xiaoy.entity.BaseBean;
@Entity
@Table(name=ConfigTable.Security.USER_ROLE_TABLENAME)
@Cache(usage = CacheConcurrencyStrategy.READ_WRITE)
public class UserRole extends BaseBean {

//	private long userId;
//	private long roleId;
	
	private User user;
	private Role role;
	
	public UserRole (){}
	
	public UserRole (long roleId){
		role = new Role(roleId);
	}
	
	/**
	 * 
	 * @param roleId 角色id
	 * @param userId 用户id
	 */
	public UserRole (long roleId,long userId){
		role = new Role(roleId);
		user = new User(userId);
	}
	
	
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) 
	@JoinColumn(name="userId")
	public User getUser() {
		return user;
	}
	public void setUser(User user) {
		this.user = user;
	}
	
	@ManyToOne(cascade = CascadeType.ALL, fetch = FetchType.LAZY) 
	@JoinColumn(name="roleId")
	public Role getRole() {
		return role;
	}
	public void setRole(Role role) {
		this.role = role;
	}
	
}
